<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        let arrItem = [];
        for (let i = 1; i <= 100; i++) {
            arrItem.push(i);
        }
        function deserailar(depth, tree, getItem) {
            if (depth == 0) {
                console.log(tree);
                return;
            } else {               
                for (let i = 0; i < 8; i++) {
                    if (tree.name & (1 << i)) {
                        let key = getItem();
                        if (!key) return;
                        tree.children.push(key);
                        deserailar(depth - 1, key, getItem)
                    }
                }
                return;
            }
        }
        let tree = getItem();
        deserailar(5, tree, getItem)
        console.log(tree);
        function getItem() {
            let v = arrItem.shift()
            if (v) {
                return {
                    name: v,
                    children: []
                }
            } else {
                return null;
            }
        }
    </script>
</body>

</html>